using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Modeling;
using System.IO;
using System.Reflection;
using System.Diagnostics;

using EastBancTech.DSL.FileSystemDefinition;

namespace EastBancTech.InstallerDefinition
{
    public partial class FolderSource
    {
        protected override void BuildFileSystemModel(FileSystemModel fileSystemModel)
        {
            if (String.IsNullOrEmpty(path))
                return;

            List<string> includes = new List<string>();
            List<string> excludes = new List<string>();

            foreach (Exclude exclude in this.FileSet.Excludes)
                excludes.Add(exclude.pattern);

            foreach (Include include in this.FileSet.Includes)
                includes.Add(include.pattern);

            String resolvedPath = path;

            if (!Path.IsPathRooted(path) && this.Store.PropertyBag.ContainsKey("BaseSourceDir"))
                resolvedPath = new DirectoryInfo(Path.Combine((String)this.Store.PropertyBag["BaseSourceDir"], path)).FullName;
            
            EastBancTech.DSL.FileSystemDefinition.Custom.FileSystemBuilder.BuildFileSystemModelFromPath(fileSystemModel, resolvedPath, includes.ToArray(), excludes.ToArray(), null);
        }

        protected override string GetFileModelName()
        {
            if (Component != null)
                return Component.Name;

            if (this.JavaWebContainer != null)
            {
                return String.Format("{0}.{1}", this.JavaWebContainer.Name, JavaWebContainerHasLibs.GetLink(this.JavaWebContainer, this).Type.ToString());                  
            }

            return base.GetFileModelName();
        }

        //public bool InclusionDecision(String filePath)
        //{
        //    if (this.FileSets.Count == 0)
        //        return true;

        //    foreach (FileSet filter in this.FileSets)
        //        if (filter.IsFileIncluded(filePath))
        //            return true;

        //    return false;

            
        //}
        
    }
}
